using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Network;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Xml.Linq;
namespace MicroMsg.UI.UserContrl
{
	public class SessionView : UserControl
	{
		public class SessionICommand : ICommand
		{
			private bool _canExecute = true;
			public event EventHandler CanExecuteChanged;
			public bool IsEnable
			{
				get
				{
					return this._canExecute;
				}
				set
				{
					if (this._canExecute != value)
					{
						EventHandler canExecuteChanged = this.CanExecuteChanged;
						if (canExecuteChanged != null)
						{
							canExecuteChanged.Invoke(this, EventArgs.Empty);
						}
					}
					this._canExecute = value;
				}
			}
			public bool CanExecute(object parameter)
			{
				return this._canExecute;
			}
			public void Execute(object parameter)
			{
				Conversation conversation_0 = parameter as Conversation;
				if (conversation_0 == null)
				{
					return;
				}
				if (MainPage.mainPageInstance == null)
				{
					return;
				}
				if (ContactMgr.getUserType(conversation_0.strUsrName) == ContactMgr.UserType.UserTypeChatRoom)
				{
					Log.smethod_5("SessionView", " ConversationMgr.delChatRoomConversation" + conversation_0.strUsrName);
					ConversationMgr.delChatRoomConversation(conversation_0.strUsrName);
					return;
				}
				if (conversation_0.strUsrName == "qmessage")
				{
					Log.smethod_5("SessionView", " ConversationMgr.delConversation" + conversation_0.strUsrName);
					QConversationMgr.QQOfflineMsgClearAll();
					return;
				}
				if (conversation_0.strUsrName == "floatbottle")
				{
					Log.smethod_5("SessionView", " ConversationMgr.delConversation" + conversation_0.strUsrName);
					ConversationMgr.delConversation("floatbottle");
					AccountMgr.ShowBottleInChat = false;
					ServiceCenter.sceneNewSync.doScene(1, syncScene.MM_NEWSYNC_SCENE_OTHER);
					return;
				}
				if (ContactMgr.getUserType(conversation_0.strUsrName) == ContactMgr.UserType.UserTypeNormal || ContactMgr.getUserType(conversation_0.strUsrName) == ContactMgr.UserType.UserTypePlugin)
				{
					Log.smethod_5("SessionView", " ConversationMgr.delConversation" + conversation_0.strUsrName);
					MainPage.mainPageInstance.mSessionView.ShowLoading(strings.Delete_Waiting);
					MainPage.mainPageInstance.get_Dispatcher().BeginInvoke(delegate
					{
						ConversationMgr.delConversation(conversation_0.strUsrName);
						MainPage.mainPageInstance.mSessionView.HideLoading();
					});
				}
			}
		}
		private const string TAG = "SessionView";
		private const string FilpGroup = "SessionFilp";
		private const int BANNER_OFFSET = 80;
		private MMObservableCollection<Conversation, SessionListItem> mDataList = new MMObservableCollection<Conversation, SessionListItem>();
		private List<Conversation> mDelayUpdateConv = new List<Conversation>();
		private EventWatcher mListChangeWatcher;
		private bool isConversationInit;
		private static ApplicationBar mBar;
		private static ApplicationBarMenuItem newSessionButton;
		private static ApplicationBarMenuItem settingButton;
		private static ApplicationBarMenuItem updateButton;
		private static ApplicationBarMenuItem webMMButton;
		private SessionView.SessionICommand mCommand;
		private bool isShowLoading;
		public bool IsMenuLoaded;
		private ClickableLayout webMM_banner;
		private Canvas banner_Layout;
		private Canvas banner_advertisement;
		private Image AdImg;
		private Button adCloseBtn;
		private StackPanel banner_ServerBulletin;
		private TextBlock serverBulletinTitle;
		private TextBlock serverBulletinContent;
		private TextBlock serverBulletinButton;
		private int AllInitNum;
		private EventWatcher m_ReqUserList;
		private bool isCheckBulletinOnInit;
		private EventWatcher bannerImgWatcher;
		private ScrollViewer svList;
		internal Grid LayoutRoot;
		internal MMListBox SessionList;
		private bool _contentLoaded;
		public SessionView()
		{
			ShowObjectInMemory.AddOneObjectRecord(this);
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.SessionView_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.SessionView_Unloaded));
			this.SessionList.IsSessionListBox = true;
			this.SessionList.mListBoxKind = MMListBoxKind.Kind_SessionList;
		}
		~SessionView()
		{
			ShowObjectInMemory.RemoveOneObjectRecord(this);
		}
		private void SessionView_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		public void SessionUnit()
		{
			this.ConversationUninit();
		}
		private void InitOtherView()
		{
			if (MainPage.mainPageInstance != null)
			{
				MainPage.mainPageInstance.getContactView();
				MainPage.mainPageInstance.getFFView();
			}
		}
		private void SessionView_Loaded(object sender, RoutedEventArgs e)
		{
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.ConversationInit();
			});
			base.get_Dispatcher().BeginInvoke(delegate
			{
				List<UITask> list = new List<UITask>();
				list.Add(new UITask(new UITaskDlg(this.InitOtherView), 0u));
				UITaskManager uITaskManager = new UITaskManager(list, null);
				uITaskManager.StartTasks(1000u);
			});
		}
		public void ConversationUpdate(Conversation conversation_0, bool isUpdateFromList = false)
		{
			if (conversation_0 == null)
			{
				return;
			}
			if (!BindHintManager.IsBindHintConv(conversation_0) && !GuideHeadSetMgr.IsSetHeadHintConv(conversation_0) && !ConversationMgr.IsSupport(conversation_0))
			{
				return;
			}
			bool flag = true;
			for (int i = 0; i < this.mDataList.get_Count(); i++)
			{
				Conversation conversation = this.mDataList[i];
				if (conversation.strUsrName == conversation_0.strUsrName)
				{
					this.mDataList.RemoveAt(i);
					IL_6B:
					if (flag)
					{
						int num = this.mDataList.get_Count();
						for (int j = 0; j < this.mDataList.get_Count(); j++)
						{
							Conversation conversation2 = this.mDataList[j];
							if (conversation_0.nTime > conversation2.nTime)
							{
								num = j;
								IL_AF:
								this.mDataList.Insert(num, conversation_0);
								goto IL_BC;
							}
						}
						goto IL_AF;
					}
					IL_BC:
					if (!isUpdateFromList)
					{
						this.SessionList.ForceComputeVisible();
						this.UpdateAllUnreadCount();
					}
					return;
				}
			}
			goto IL_6B;
		}
		public void DelayUpdateConversation()
		{
			int num = 2147483647;
			int num2 = 0;
			while (num2 < num && num2 < this.mDelayUpdateConv.get_Count())
			{
				this.ConversationUpdate(Enumerable.First<Conversation>(this.mDelayUpdateConv), true);
				this.mDelayUpdateConv.RemoveAt(0);
				num2++;
				num2++;
			}
			if (this.mDelayUpdateConv.get_Count() == 0)
			{
				this.SessionList.ForceComputeVisible();
				this.UpdateAllUnreadCount();
			}
			else
			{
				base.get_Dispatcher().BeginInvoke(delegate
				{
					List<UITask> list = new List<UITask>();
					list.Add(new UITask(new UITaskDlg(this.DelayUpdateConversation), 0u));
					UITaskManager uITaskManager = new UITaskManager(list, null);
					uITaskManager.StartTasks(400u);
				});
			}
			ScrollViewer scrollview = this.SessionList.getScrollViewer();
			if (scrollview != null)
			{
				base.get_Dispatcher().BeginInvoke(delegate
				{
					scrollview.ScrollToVerticalOffset(this.svList.get_VerticalOffset());
				});
			}
		}
		public void ConversationUpdate(ObservableCollection<Conversation> cvsList)
		{
			if (cvsList == null)
			{
				return;
			}
			int num = 0;
			cvsList = Enumerable.OrderBy<Conversation, long>(cvsList, (Conversation conversation_0) => conversation_0.nTime).ToObservableCollection<Conversation>();
			for (int i = cvsList.get_Count() - 1; i >= 0; i--)
			{
				Conversation conversation = cvsList.get_Item(i);
				if (num < 7)
				{
					this.ConversationUpdate(conversation, true);
				}
				else
				{
					this.mDelayUpdateConv.Add(conversation);
				}
				num++;
			}
			this.SessionList.ForceComputeVisible();
			this.UpdateAllUnreadCount();
			base.get_Dispatcher().BeginInvoke(delegate
			{
				List<UITask> list = new List<UITask>();
				list.Add(new UITask(new UITaskDlg(this.DelayUpdateConversation), 0u));
				UITaskManager uITaskManager = new UITaskManager(list, null);
				uITaskManager.StartTasks(1000u);
			});
		}
		public void ConversationDelete(string userName)
		{
			for (int i = 0; i < this.mDataList.get_Count(); i++)
			{
				Conversation conversation = this.mDataList[i];
				if (conversation.strUsrName == userName)
				{
					this.mDataList.RemoveAt(i);
					IL_3F:
					this.SessionList.ForceComputeVisible();
					this.UpdateAllUnreadCount();
					return;
				}
			}
			goto IL_3F;
		}
		private void UpdateAllUnreadCount()
		{
			int num = 0;
			if (this.mDataList != null && this.mDataList.get_Count() > 0)
			{
				for (int i = 0; i < this.mDataList.get_Count(); i++)
				{
					Conversation conversation = this.mDataList[i];
					num += conversation.nUnReadCount;
				}
			}
			else
			{
				num = 0;
			}
			TileManager.SetTileNumber(num);
			MainPage mainPageInstance = MainPage.mainPageInstance;
			if (mainPageInstance == null)
			{
				return;
			}
			mainPageInstance.ShowUnreadMsgCount(num);
		}
		private void ConversationInit()
		{
			if (this.isConversationInit)
			{
				return;
			}
			Log.smethod_5("SessionView", "ServiceCenter.conversationMgr.getList() start");
			this.ConversationUpdate(ServiceCenter.conversationMgr.getList());
			Log.smethod_5("SessionView", "ServiceCenter.conversationMgr.getList() end");
			this.mDataList.Bind(this.SessionList);
			if (this.mDataList.get_Count() <= 0)
			{
				MainPage rootPage = this.GetRootPage<MainPage>();
				if (rootPage != null)
				{
					rootPage.DoNewSync();
				}
			}
			this.mListChangeWatcher = new EventWatcher(this, this, new EventHandlerDelegate(this.OnConversationChange));
			EventCenter.registerEventWatcher(EventConst.ON_CONVERSATION_LIST_CHNAGE, this.mListChangeWatcher);
			EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONVERSATION_DEL, this.mListChangeWatcher);
			Log.smethod_5("SessionView", "registerEventWatcher EventConst.ON_CONVERSATION_LIST_CHNAGE");
			this.isConversationInit = true;
		}
		private void ConversationUninit()
		{
			if (!this.isConversationInit)
			{
				return;
			}
			EventCenter.removeEventWatcher(EventConst.ON_CONVERSATION_LIST_CHNAGE, this.mListChangeWatcher);
			EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONVERSATION_DEL, this.mListChangeWatcher);
			Log.smethod_5("SessionView", "removeEventWatcher EventConst.ON_CONVERSATION_LIST_CHNAGE");
			this.isConversationInit = false;
		}
		private void OnConversationChange(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
			List<Conversation> listObject = evtArgs.getListObject<Conversation>();
			if (listObject == null)
			{
				return;
			}
			using (List<Conversation>.Enumerator enumerator = listObject.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Conversation current = enumerator.get_Current();
					if (current != null)
					{
						if (evtArgs.mEventID == EventConst.ON_CONVERSATION_LIST_CHNAGE)
						{
							this.ConversationUpdate(current, false);
						}
						else
						{
							if (evtArgs.mEventID == EventConst.ON_STORAGE_CONVERSATION_DEL)
							{
								Log.smethod_5("SessionView", "ConversationDelete In Ui List" + current.strUsrName);
								this.ConversationDelete(current.strUsrName);
							}
						}
					}
				}
			}
		}
		public static ApplicationBar GetApplicationBar(bool useCache = true)
		{
			if (SessionView.mBar != null && useCache)
			{
				if (!SessionView.mBar.get_IsVisible())
				{
					SessionView.mBar.set_IsVisible(true);
				}
				return SessionView.mBar;
			}
			SessionView.mBar = new ApplicationBar();
			SessionView.mBar.set_IsMenuEnabled(true);
			SessionView.mBar.set_IsVisible(true);
			SessionView.mBar.set_Mode(1);
			SessionView.newSessionButton = new ApplicationBarMenuItem(strings.ChatCreateNew);
			SessionView.newSessionButton.add_Click(new EventHandler(SessionView.newSessionButton_Click));
			SessionView.mBar.get_MenuItems().Add(SessionView.newSessionButton);
			SessionView.webMMButton = new ApplicationBarMenuItem(strings.WebMM_Name);
			SessionView.webMMButton.add_Click(new EventHandler(SessionView.webMMButton_Click));
			SessionView.mBar.get_MenuItems().Add(SessionView.webMMButton);
			SessionView.settingButton = new ApplicationBarMenuItem(strings.COM_Setting);
			SessionView.settingButton.add_Click(new EventHandler(SessionView.settingButton_Click));
			SessionView.mBar.get_MenuItems().Add(SessionView.settingButton);
			if (MainPage.mainPageInstance != null && MainPage.mainPageInstance.m_UpdateInfo != null)
			{
				SessionView.updateButton = new ApplicationBarMenuItem(strings.Set_AboutMM_Update);
				SessionView.updateButton.add_Click(new EventHandler(SessionView.btnUpdateVersion_Click));
				SessionView.mBar.get_MenuItems().Add(SessionView.updateButton);
			}
			return SessionView.mBar;
		}
		public void OnLanguageChange()
		{
			if (SessionView.newSessionButton != null)
			{
				SessionView.newSessionButton.set_Text(strings.ChatCreateNew);
			}
			if (SessionView.settingButton != null)
			{
				SessionView.settingButton.set_Text(strings.COM_Setting);
			}
			if (SessionView.updateButton != null)
			{
				SessionView.updateButton.set_Text(strings.Set_AboutMM_Update);
			}
			if (SessionView.webMMButton != null)
			{
				SessionView.webMMButton.set_Text(strings.WebMM_Name);
			}
		}
		private static void btnUpdateVersion_Click(object sender, EventArgs e)
		{
			if (MainPage.mainPageInstance != null && MainPage.mainPageInstance.m_UpdateInfo != null)
			{
				string text = (MainPage.mainPageInstance.m_UpdateInfo.PackSize * 1.0 / 1048576.0).ToString();
				int num = (text.get_Length() > 3) ? 3 : text.get_Length();
				text = text.Substring(0, num);
				MMMessageBox mMMessageBox = MMMessageBox.Show(strings.Set_AboutMM_HasNewVersion, string.Concat(new string[]
				{
					MainPage.mainPageInstance.m_UpdateInfo.PackDescription,
					"\r\n",
					strings.Set_AboutMM_PackageSize,
					text,
					"MB"
				}), true, strings.Set_AboutMM_Update, strings.COM_Cancel);
				mMMessageBox.ReturnEvent = new DlgReturnEvent(MainPage.mainPageInstance.updateInfoDlgReturn);
			}
		}
		private static void settingButton_Click(object sender, EventArgs e)
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			BasePage basePage = phoneApplicationFrame.get_Content() as BasePage;
			if (basePage != null)
			{
				basePage.GoToPage("/Source/UI/Setting/SettingMainPage.xaml", null, false);
			}
		}
		private static void webMMButton_Click(object sender, EventArgs e)
		{
			ToolFunction.GotoPageForUserControl("/Source/UI/WebMM/WebMMStartPage.xaml", null, false);
		}
		private void LogoutButton_Click(object sender, EventArgs e)
		{
			MainPage.initLogOut();
		}
		private static void newSessionButton_Click(object sender, EventArgs e)
		{
			object[] array = new object[4];
			array[0] = AddPeoplePage.AddPeopleType.CreateFromMainPage;
			array[1] = null;
			List<string> list = new List<string>();
			list.Add(AccountMgr.getCurAccount().strUsrName);
			array[2] = list;
			array[3] = null;
			MainPage mainPage = ToolFunction.GetRootPage() as MainPage;
			if (mainPage == null)
			{
				return;
			}
			mainPage.GoToPage("/Source/UI/Chat/AddPeoplePage.xaml", array, false);
		}
		private void cancelButton_Click(object sender, EventArgs e)
		{
		}
		public void StartChat(string userName, string nickName)
		{
			if (MainPage.mainPageInstance == null)
			{
				return;
			}
			ChatContainerPage.GoToChatPage(MainPage.mainPageInstance, userName, null, null, null);
		}
		private void OpenQConvView()
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			BasePage basePage = phoneApplicationFrame.get_Content() as BasePage;
			basePage.GoToPage("/Source/Plugin/QQOfflineMsg/UI/QQSessionView.xaml", null, false);
		}
		private void OpenBConvView()
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			BasePage basePage = phoneApplicationFrame.get_Content() as BasePage;
			basePage.GoToPage("/Source/Plugin/DriftBottle/UI/BottlesListPage.xaml", new object[]
			{
				BottlesListPage.BottleListPageEntryType.fromConvList
			}, false);
		}
		private void OpenNewsView(int unReadCount)
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			BasePage basePage = phoneApplicationFrame.get_Content() as BasePage;
			basePage.GoToPage("/Source/Plugin/TXNews/UI/NewsSessionView.xaml", new object[]
			{
				unReadCount
			}, false);
		}
		private void OpenQQMailView(int unReadCount)
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			BasePage basePage = phoneApplicationFrame.get_Content() as BasePage;
			basePage.GoToPage("/Source/Plugin/QQMail/UI/QQMailSessionView.xaml", new object[]
			{
				unReadCount
			}, false);
		}
		private void OpenMasssendView()
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			BasePage basePage = phoneApplicationFrame.get_Content() as BasePage;
			basePage.GoToPage("/Source/Plugin/MassSend/UI/MessagesListPage.xaml", null, false);
		}
		private void OpenBlogAppView()
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			BasePage basePage = phoneApplicationFrame.get_Content() as BasePage;
			basePage.GoToPage("/Source/Plugin/TXBlogRead/UI/TXBlogReadView.xaml", null, false);
		}
		private void SessionListItem_ItemClick(object sender, object object_0)
		{
			Conversation conversation = object_0 as Conversation;
			if (conversation == null)
			{
				return;
			}
			if (GuideHeadSetMgr.IsSetHeadHintConv(conversation))
			{
				GuideHeadSetMgr.GotoSetHeadImg();
				return;
			}
			if (BindHintManager.IsBindHintConv(conversation))
			{
				this.OpenBindGuide(conversation);
				return;
			}
			if (ConversationMgr.IsQmessage(conversation))
			{
				this.OpenQConvView();
				return;
			}
			if (ConversationMgr.IsBmessage(conversation))
			{
				this.OpenBConvView();
				return;
			}
			if (ContactHelper.isNewsContact(conversation.strUsrName))
			{
				this.OpenNewsView(conversation.nUnReadCount);
				return;
			}
			if (ContactHelper.isQQMailContact(conversation.strUsrName))
			{
				this.OpenQQMailView(conversation.nUnReadCount);
				return;
			}
			if (ConversationMgr.IsMassMsg(conversation))
			{
				this.OpenMasssendView();
				return;
			}
			if (ContactHelper.isBlogAppContact(conversation.strUsrName))
			{
				this.OpenBlogAppView();
				return;
			}
			if (MainPage.mainPageInstance == null)
			{
				return;
			}
			ChatContainerPage.GoToChatPage(MainPage.mainPageInstance, conversation.strUsrName, null, null, null);
		}
		private void OpenBindGuide(Conversation conversation_0)
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			BasePage page = phoneApplicationFrame.get_Content() as BasePage;
			BindHintManager.GoToBinding(page, conversation_0);
		}
		private SessionView.SessionICommand getCommand()
		{
			if (this.mCommand == null)
			{
				this.mCommand = new SessionView.SessionICommand();
			}
			return this.mCommand;
		}
		private void DeleteSessionMenu_Loaded(object sender, RoutedEventArgs e)
		{
			MainPage.mainPageInstance.mNBackKeyRelayCount++;
			this.IsMenuLoaded = true;
			MenuItem menuItem = sender as MenuItem;
			if (menuItem != null && menuItem.CommandParameter != null)
			{
				Conversation conversation = menuItem.CommandParameter as Conversation;
				if (conversation.strUsrName == "floatbottle")
				{
					menuItem.Header = strings.Float_Botlle_delete_bottleentry;
				}
				else
				{
					if (conversation.strUsrName == "qmessage")
					{
						menuItem.Header = strings.Plugin_QQOffline_delete_entry;
					}
				}
				menuItem.Command = this.getCommand();
				return;
			}
		}
		public void ShowLoading(string info)
		{
			if (this.isShowLoading)
			{
				return;
			}
			MainPage rootPage = this.GetRootPage<MainPage>();
			if (rootPage == null)
			{
				return;
			}
			this.isShowLoading = true;
			ProcessingCover.getProgressBar(rootPage.LayoutRoot, info, null, false, false, null);
		}
		public void HideLoading()
		{
			if (!this.isShowLoading)
			{
				return;
			}
			MainPage rootPage = this.GetRootPage<MainPage>();
			if (rootPage == null)
			{
				return;
			}
			this.isShowLoading = false;
			ProcessingCover.releaseProgressBar(rootPage.LayoutRoot);
		}
		public void LockFilp()
		{
			MMHubTileService.FreezeGroup("SessionFilp");
		}
		public void UnLockFilp()
		{
			MMHubTileService.UnfreezeGroup("SessionFilp");
		}
		private void DeleteSessionMenu_Unloaded(object sender, RoutedEventArgs e)
		{
			if (MainPage.mainPageInstance != null)
			{
				MainPage.mainPageInstance.mNBackKeyRelayCount--;
			}
			this.IsMenuLoaded = false;
		}
		public void ScrollToFirst()
		{
			if (this.mDataList == null || this.mDataList.get_Count() <= 0)
			{
				return;
			}
			if (this.SessionList == null)
			{
				return;
			}
			ScrollViewer scrollViewer = this.SessionList.getScrollViewer();
			if (scrollViewer == null)
			{
				return;
			}
			scrollViewer.ScrollToVerticalOffset(0.0);
		}
		private bool IsAllInit()
		{
			return this.AllInitNum >= 8;
		}
		private void onAllInit()
		{
			if (!this.isCheckBulletinOnInit)
			{
				this.onEventServerBulletinChanged(null, null);
				this.isCheckBulletinOnInit = true;
			}
		}
		private void loadedOne()
		{
			this.AllInitNum++;
			if (this.IsAllInit())
			{
				this.onAllInit();
			}
		}
		private void banner_Layout_Loaded(object sender, RoutedEventArgs e)
		{
			this.banner_Layout = (sender as Canvas);
			this.loadedOne();
		}
		private void banner_advertisement_Loaded(object sender, RoutedEventArgs e)
		{
			this.banner_advertisement = (sender as Canvas);
			this.loadedOne();
		}
		private void webMM_banner_Loaded(object sender, RoutedEventArgs e)
		{
			this.webMM_banner = (sender as ClickableLayout);
		}
		private void AdImg_Loaded(object sender, RoutedEventArgs e)
		{
			this.AdImg = (sender as Image);
			this.loadedOne();
		}
		private void adCloseBtn_Loaded(object sender, RoutedEventArgs e)
		{
			this.adCloseBtn = (sender as Button);
			this.loadedOne();
		}
		private void banner_ServerBulletin_Loaded(object sender, RoutedEventArgs e)
		{
			this.banner_ServerBulletin = (sender as StackPanel);
			this.loadedOne();
		}
		private void serverBulletinTitle_Loaded(object sender, RoutedEventArgs e)
		{
			this.serverBulletinTitle = (sender as TextBlock);
			this.loadedOne();
		}
		private void serverBulletinContent_Loaded(object sender, RoutedEventArgs e)
		{
			this.serverBulletinContent = (sender as TextBlock);
			this.loadedOne();
		}
		private void serverBulletinButton_Loaded(object sender, RoutedEventArgs e)
		{
			this.serverBulletinButton = (sender as TextBlock);
			this.loadedOne();
		}
		private void webMM_banner_click(object sender, RoutedEventArgs e)
		{
			ToolFunction.GotoPageForUserControl("/Source/UI/WebMM/WebMMLogoutPage.xaml", null, false);
		}
		public void setWebMMState(bool isOnline)
		{
			ScrollViewer scrollViewer = this.SessionList.getScrollViewer();
			if (isOnline)
			{
				this.initWebMMWatcher();
				this.webMM_banner.set_Visibility(0);
				if (scrollViewer != null)
				{
					scrollViewer.set_Height(548.0);
					return;
				}
			}
			else
			{
				this.unInitWebMMWatcher();
				this.webMM_banner.set_Visibility(1);
				if (scrollViewer != null)
				{
					scrollViewer.set_Height(650.0);
				}
			}
		}
		private void initWebMMWatcher()
		{
			this.m_ReqUserList = new EventWatcher(this, null, new EventHandlerDelegate(this.onReqUserList));
			EventCenter.registerEventWatcher(EventConst.SYS_MSG_WEB_WX_STATUSNOTIFY, this.m_ReqUserList);
		}
		private void unInitWebMMWatcher()
		{
			if (this.m_ReqUserList != null)
			{
				EventCenter.removeEventWatcher(EventConst.SYS_MSG_WEB_WX_STATUSNOTIFY, this.m_ReqUserList);
				this.m_ReqUserList = null;
			}
		}
		private void onReqUserList(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			string text = evtArgs.mObject as string;
			if (text == null)
			{
				return;
			}
			XDocument xDocument = XDocument.Parse(text);
			XElement xElement = xDocument.Element("msg");
			if (xElement != null)
			{
				XElement xElement2 = xElement.Element("op");
				if (xElement2 != null)
				{
					int num = int.Parse(xElement2.Attribute("id").get_Value());
					if (num == 1)
					{
						XElement xElement3 = xElement2.Element("username");
						if (xElement3 != null)
						{
							string value = xElement3.get_Value();
							ConversationMgr.setUnreadCount(value, 0, true);
							return;
						}
					}
					else
					{
						if (num == 3)
						{
							NetSceneStatusNotify netSceneStatusNotify = new NetSceneStatusNotify();
							string text2 = "";
							if (this.mDataList != null)
							{
								using (IEnumerator<Conversation> enumerator = this.mDataList.GetEnumerator())
								{
									while (enumerator.MoveNext())
									{
										Conversation current = enumerator.get_Current();
										if (!(current.strUsrName == "SetHeadHint@SetHeadHint") && !(current.strUsrName == "BindHint@BindHint") && !ToolFunction.systemPluginName.Contains(current.strUsrName))
										{
											text2 = text2 + current.strUsrName + ",";
										}
									}
								}
							}
							if (text2.EndsWith(","))
							{
								text2 = text2.Substring(0, text2.get_Length() - 1);
							}
							netSceneStatusNotify.doScene(MMStatusNotifyType.MM_STATUSNOTIFY_CHATLISTRESP, AccountMgr.curUserName, text2);
						}
					}
				}
			}
		}
		private void updateBulletinText()
		{
			if (!this.IsAllInit())
			{
				return;
			}
			if (!NetworkDeviceWatcher.isNetworkAvailable())
			{
				this.serverBulletinTitle.set_Text(strings.Bulletin_Disconnect_Title);
				this.serverBulletinContent.set_Text(strings.Bulletin_Disconnect_Desc);
				return;
			}
			if (ServerBulletin.isFaultMode())
			{
				this.serverBulletinTitle.set_Text(strings.Bulletin_OOB_Title);
				this.serverBulletinContent.set_Text(strings.Bulletin_OOB_Desc);
			}
		}
		public void onEventServerBulletinChanged(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (!this.IsAllInit())
			{
				return;
			}
			this.updateBulletinText();
			if (ServerBulletin.isFaultMode())
			{
				this.banner_ServerBulletin.set_Visibility(0);
				this.showBanner();
			}
			if (watcher != null && this.canHideBulletin() && this.banner_ServerBulletin.get_Visibility() == null)
			{
				this.hideBanner();
				this.banner_ServerBulletin.set_Visibility(1);
			}
		}
		public void onEventLanguageChanged(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (!this.IsAllInit())
			{
				return;
			}
			this.updateBulletinText();
		}
		private bool canHideBulletin()
		{
			return NetworkDeviceWatcher.isNetworkAvailable() && !ServerBulletin.isFaultMode();
		}
		public void updateBulletinOnNetStatusChanged()
		{
			if (!this.IsAllInit())
			{
				return;
			}
			this.updateBulletinText();
			if (NetworkDeviceWatcher.isNetworkAvailable())
			{
				if (this.canHideBulletin() && this.banner_ServerBulletin.get_Visibility() == null)
				{
					this.hideBanner();
					this.banner_ServerBulletin.set_Visibility(1);
					return;
				}
			}
			else
			{
				this.banner_ServerBulletin.set_Visibility(0);
				this.showBanner();
			}
		}
		private void onServerBulletin_Click(object sender, RoutedEventArgs e)
		{
			if (!this.IsAllInit())
			{
				return;
			}
			if (!NetworkDeviceWatcher.isNetworkAvailable())
			{
				BasePage rootPage = this.GetRootPage<BasePage>();
				if (rootPage != null)
				{
					rootPage.GoToPage("/Source/UI/Bulletin/LocalBulletinPage.xaml", null, false);
					return;
				}
			}
			else
			{
				object[] object_ = new object[]
				{
					ServerBulletin.getBulletinUrl(AccountMgr.strUsrName, R.GetCurrentLanguage())
				};
				BasePage rootPage2 = this.GetRootPage<BasePage>();
				if (rootPage2 != null)
				{
					rootPage2.GoToPage("/Source/UI/Bulletin/ServerBulletinPage.xaml", object_, false);
				}
			}
		}
		private void showBanner()
		{
			if (!this.IsAllInit())
			{
				return;
			}
			if (this.banner_Layout.get_Visibility() == null)
			{
				return;
			}
			this.banner_Layout.set_Visibility(0);
			ScrollViewer scrollViewer = this.SessionList.getScrollViewer();
			if (scrollViewer != null)
			{
				scrollViewer.set_Height(548.0);
			}
		}
		private void hideBanner()
		{
			if (!this.IsAllInit())
			{
				return;
			}
			if (this.banner_Layout.get_Visibility() == 1)
			{
				return;
			}
			if (this.banner_ServerBulletin.get_Visibility() == null && this.banner_advertisement.get_Visibility() == null)
			{
				return;
			}
			this.banner_Layout.set_Visibility(1);
			ScrollViewer scrollViewer = this.SessionList.getScrollViewer();
			if (scrollViewer != null)
			{
				scrollViewer.set_Height(650.0);
			}
		}
		private void offsetControl(UserControl control, int offset)
		{
			Thickness margin = control.get_Margin();
			margin.set_Top(margin.get_Top() + (double)offset);
			control.set_Margin(margin);
		}
		public void InitBanner()
		{
			BannerManager.LoadBanner();
			if (BannerManager.IsBannerShouldShow())
			{
				Log.smethod_5("SessionView", "BannerShouldShow=true");
				this.OnShowBanner();
			}
			else
			{
				Log.smethod_5("SessionView", "BannerShouldShow=false");
			}
			this.bannerImgWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.OnNeedShowBanner));
			EventCenter.registerEventWatcher(EventConst.ON_UI_NEED_SHOW_BANNER, this.bannerImgWatcher);
		}
		private void AdImg_Tap(object sender, GestureEventArgs e)
		{
			if (!this.IsAllInit())
			{
				return;
			}
			Log.smethod_5("SessionView", "AdImg_MouseLeftButtonUp");
			string bannerUrl = BannerManager.GetBannerUrl();
			if (string.IsNullOrEmpty(bannerUrl))
			{
				Log.smethod_5("SessionView", "AdImg_MouseLeftButtonUp url=null");
				return;
			}
			ToolFunction.GotoWebLink(bannerUrl);
			OpLogMgr.OpSendPsmStat(PSMSTAT_KEY.PSMSTAT_KEY_CLICK, BannerManager.GetBannerTipId());
			BannerManager.CloseBanner();
			this.OnCloseBanner();
		}
		private void OnNeedShowBanner(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (!this.IsAllInit())
			{
				return;
			}
			Log.smethod_5("SessionView", "OnNeedShowBanner");
			if (BannerManager.IsBannerShouldShow())
			{
				this.OnShowBanner();
			}
		}
		public void OnShowBanner()
		{
			if (!this.IsAllInit())
			{
				return;
			}
			BitmapImage bitmapImage = ImageCacheMgr.loadImage(BannerManager.GetBannerPath(), ImageCacheType.MsgImg);
			if (bitmapImage == null)
			{
				return;
			}
			if (BannerManager.isCanClose())
			{
				this.adCloseBtn.set_Visibility(0);
			}
			else
			{
				this.adCloseBtn.set_Visibility(1);
			}
			this.AdImg.set_Source(bitmapImage);
			this.banner_advertisement.set_Visibility(0);
			this.showBanner();
		}
		public void OnCloseBanner()
		{
			if (!this.IsAllInit())
			{
				return;
			}
			if (this.banner_advertisement.get_Visibility() != null)
			{
				return;
			}
			this.hideBanner();
			this.banner_advertisement.set_Visibility(1);
		}
		private void adCloseBtn_Click(object sender, RoutedEventArgs e)
		{
			BannerManager.CloseBanner();
			this.OnCloseBanner();
			OpLogMgr.OpSendPsmStat(PSMSTAT_KEY.PSMSTAT_KEY_CLOSE, BannerManager.GetBannerTipId());
		}
		public void OnBindSuccess()
		{
			if (this.mDataList != null && this.mDataList.get_Count() > 0)
			{
				using (IEnumerator<Conversation> enumerator = this.mDataList.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						Conversation current = enumerator.get_Current();
						if (BindHintManager.IsBindHintConv(current))
						{
							StorageMgr.converation.method_2(current);
							break;
						}
					}
				}
				return;
			}
		}
		public void RemoveGuideHeadSetItem()
		{
			if (this.mDataList != null && this.mDataList.get_Count() > 0)
			{
				using (IEnumerator<Conversation> enumerator = this.mDataList.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						Conversation current = enumerator.get_Current();
						if (GuideHeadSetMgr.IsSetHeadHintConv(current))
						{
							StorageMgr.converation.method_2(current);
							break;
						}
					}
				}
				return;
			}
		}
		private void svList_Loaded(object sender, RoutedEventArgs e)
		{
			this.svList = (sender as ScrollViewer);
			if (this.svList != null)
			{
				this.svList.remove_Loaded(new RoutedEventHandler(this.svList_Loaded));
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Session/SessionView.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.SessionList = (MMListBox)base.FindName("SessionList");
		}
	}
}
